<%@ page import="com.oval.util.JspHelper" %>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="com.oval.foundation.util.*" %>
<%@ page import="com.oval.foundation.engine.*" %>
<%@ page import="com.oval.util.*" %>
<%@ page contentType = "text/html;charset=UTF-8" %>
<%
  String flag = "";
  String[] arrId = request.getParameterValues("checkedIds");  
  UserInfo a_user = new UserInfo(session.getId(),
                                 UserInfo.CENTER_APP,
                                 new Integer(-1),
                                 new Integer(-1),
                                 "CONSOLE"
                                 );
 
  if(arrId != null && request.getParameter("actionname") != null && request.getParameter("actionname").equals("delete"))
  {
    String names = "'-1'";
    for(int j=0;j<arrId.length;j++)
    {
      names += ",'";
      names += arrId[j] + "'";
    }
    String whereclause = " and ovaltable.tableid in (" + names + ")";
    
    OvalDeleteAPI oda = new OvalDeleteAPI();
    oda.setBI(a_user,new Long(-1000),new Integer(0));
    HashMap fm = oda.deleteData("ovovaltable",whereclause,null,null);
    if(!(((Boolean)(fm.get("IsSuccess"))).booleanValue()))
      flag = "Delete Table Failed!";
    else
      flag = "Delete Table Successfully!";           
  } else if(request.getParameter("actionname") != null && request.getParameter("actionname").equals("save")){     
    String tabletype = request.getParameter("tabletype");
    String tablename = request.getParameter("tablename");
    String module = request.getParameter("module");
    String tabledesccn = OvalEncode.convertEncode(request.getParameter("tabledesccn"),"iso-8859-1","utf-8");
  	String tabledescen = request.getParameter("tabledescen");
  	String tabledescjp = OvalEncode.convertEncode(request.getParameter("tabledescjp"),"iso-8859-1","utf-8");
    HashMap hm1 = new HashMap();
    hm1.put("app","DRP");
    hm1.put("tabletype",tabletype);
    hm1.put("tablename",tablename);
    if(module != null)
      hm1.put("module",module);
    hm1.put("tabledesc",tabledesccn);
    hm1.put("languagecode","cn");
    HashMap hm2 = new HashMap();
    hm2.put("app","DRP");
    hm2.put("tabletype",tabletype);
    hm2.put("tablename",tablename);
    if(module != null)
      hm2.put("module",module);
    hm2.put("tabledesc",tabledescen);
    hm2.put("languagecode","en");
    HashMap hm3 = new HashMap();
    hm3.put("app","DRP");
    hm3.put("tabletype",tabletype);
    hm3.put("tablename",tablename);
    if(module != null)
      hm3.put("module",module);
    hm3.put("tabledesc",tabledescjp);
    hm3.put("languagecode","jp");
    OvalSaveAPI osa = new OvalSaveAPI();
    osa.setBI(a_user,new Long(-1000),new Integer(0));
    OvalCustomTable table1 = new OvalCustomTable(hm1);
    OvalCustomTable table2 = new OvalCustomTable(hm2);
    OvalCustomTable table3 = new OvalCustomTable(hm3);
    String flag1 = osa.saveData(hm1,"ovovaltable");
    if(flag1.equals("1"))
    {
      OvalCustomTableEngine.addTable(table1.getTableIndex(),table1);
      flag1 = "Successfully!";
    }
    String flag2 = osa.saveData(hm2,"ovovaltable");
    if(flag2.equals("1"))
    {
      OvalCustomTableEngine.addTable(table2.getTableIndex(),table2);
      flag2 = "Successfully!";
    }
    String flag3 = osa.saveData(hm3,"ovovaltable");
    if(flag3.equals("1"))
    {
      OvalCustomTableEngine.addTable(table3.getTableIndex(),table3);
      flag3 = "Successfully!";
    }
    flag = "Save Table(CN):" + flag1 + "<br>Save Table(EN):" + flag2 + "<br>Save Table(JP):" + flag3;  
  } else if(request.getParameter("actionname") != null && request.getParameter("actionname").equals("edit")){
    String tabletype = request.getParameter("tabletype");
    String tablename = request.getParameter("tablename");
    String module = request.getParameter("module");
    String tabledesccn = OvalEncode.convertEncode(request.getParameter("tabledesccn"),"iso-8859-1","utf-8");
  	String tabledescen = request.getParameter("tabledescen");
  	String tabledescjp = OvalEncode.convertEncode(request.getParameter("tabledescjp"),"iso-8859-1","utf-8");
    String enid = request.getParameter("edit_enid");
    String cnid = request.getParameter("edit_cnid");
    String jpid = request.getParameter("edit_jpid");
    Integer enidInt = new Integer(enid);
    Integer cnidInt = new Integer(cnid);
    Integer jpidInt = new Integer(jpid);
    HashMap hm1 = new HashMap();
    hm1.put("tableid", cnidInt);
    hm1.put("app","DRP");
    hm1.put("tabletype",tabletype);
    hm1.put("tablename",tablename);
    if(module != null)
      hm1.put("module",module);
    hm1.put("tabledesc",tabledesccn);
    hm1.put("languagecode","cn");
    HashMap hm2 = new HashMap();
    hm2.put("tableid", enidInt);
    hm2.put("app","DRP");
    hm2.put("tabletype",tabletype);
    hm2.put("tablename",tablename);
    if(module != null)
      hm2.put("module",module);
    hm2.put("tabledesc",tabledescen);
    hm2.put("languagecode","en");
    HashMap hm3 = new HashMap();
    hm3.put("tableid", jpidInt);
    hm3.put("app","DRP");
    hm3.put("tabletype",tabletype);
    hm3.put("tablename",tablename);
    if(module != null)
      hm3.put("module",module);
    hm3.put("tabledesc",tabledescjp);
    hm3.put("languagecode","jp");
    OvalSaveAPI osa = new OvalSaveAPI();
    osa.setBI(a_user,new Long(-1000),new Integer(0));
    OvalCustomTable table1 = new OvalCustomTable(hm1);
    OvalCustomTable table2 = new OvalCustomTable(hm2);
    OvalCustomTable table3 = new OvalCustomTable(hm3);
    String flag1 = osa.saveData(hm1,"ovovaltable");
    if(flag1.equals("1"))
    {
      OvalCustomTableEngine.addTable(table1.getTableIndex(),table1);
      flag1 = "Successfully!";
    }
    String flag2 = osa.saveData(hm2,"ovovaltable");
    if(flag2.equals("1"))
    {
      OvalCustomTableEngine.addTable(table2.getTableIndex(),table2);
      flag2 = "Successfully!";
    }
    String flag3 = osa.saveData(hm3,"ovovaltable");
    if(flag3.equals("1"))
    {
      OvalCustomTableEngine.addTable(table3.getTableIndex(),table3);
      flag3 = "Successfully!";
    }
    flag = "Edit Table(CN):" + flag1 + "<br>Edit Table(EN):" + flag2 + "<br>Edit Table(JP):" + flag3;  
}

%>

<html>
<head>
<title>e-manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/chinese/csscontent.css" type="text/css"> 
<script language="JavaScript" src="../css/chinese/script.js"></script>
<script language="JavaScript">
function page_back()
{
  self.location.href = "tableSummary.jsp";
}

</script>
</head>
<body>
<form name="frm">
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
  <tr> 
    <td class="td_title_bg">
     <div align="center">
       Operate Message
     </div>     
    </td>
  </tr>
  <tr class="td_bg_row"> 
    <td class="text">
     <div align="center">
       <%=JspHelper.filterNull( flag )%>
     </div>
    </td>
  </tr>
  <tr> 
    <td class="td_title_bg">
     <div align="center">
       <input type="button" name="BACK" value="BACK" onclick="javascript:page_back()">
     </div>     
    </td>
  </tr>
</table>
</form>
</body>
</html>

